< previous page page_176 next page >

Page 176
The second method of creating a new procedure is to position your cursor on a blank line in the code window and type in Private Sub EmployeeDisplay and then press the Enter key. This adds a new procedure into the code window. Now all you have to do is write the code for the EmployeeDisplay procedure.
EXERCISE
Write Your Own Procedure
1. Select the Employee Information form and double-click it in the Project Explorer window.
2. Open up a code window for this form.
3. Add the EmployeeDisplay procedure using one of the methods described previously.
4. Add the following code in this procedure:
Private Sub EmployeeDisplay()
Dim strName As String

strName = txtLast.Text & ", " & txtFirst.Text

MsgBox strName
End Sub
analysis.gifIn this routine, you get the last name from the txtLast text box and the first name from the txtFirst text box. The two values are then concatenated together with a comma in the middle.

Calling Procedures
To call a procedure or function from another procedure or function, you simply put the name of the procedure on a line by itself, like so:
9f31265bb40b592b1929e18a47ab28e5.gif
EmployeeDisplay
In addition, you can put the keyword Call in front of the name of the procedure:
9f31265bb40b592b1929e18a47ab28e5.gif
Call EmployeeDisplay
The preferred method is to place the Call keyword in front of the call to the procedure. This helps you distinguish that its a call to a procedure and not just a Visual Basic statement or a function call. Lets now call the EmployeeDisplay procedure you just created.

 
< previous page page_176 next page >

If you like this book, buy it!